var apiHost = wx.getStorageSync("apiHost");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetail : [],
    flaghear:'',        //是否团长
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var orderNo = options.orderNo;        //订单编号
    // var orderNo = '201806252357409979';        //订单编号
    
    var flaghear = options.flaghear;      //是否是团长
  
    if (flaghear!=undefined){
      that.setData({
        flaghear: flaghear
      });
    }
    that.initOrderDetail(orderNo);
  },

  /**
   * 初始化订单信息
   */
  initOrderDetail: function (orderNo){
    var that = this;
    wx.showLoading({
      title: '玩命加载中',
      icon: "loading",
      mask: true
    })
    wx.request({
      url: apiHost + 'hpp/order/detail',
      method: 'GET',
      header: {
        "contenr-type": "application/json"
      },
      data: {
        orderNo: orderNo
      },
      success: function (res) {
        console.log(res)
        var code = res.data.code;
        var msg = res.data.errMsg;
        if (code == "10000") {
          var orderDetail = res.data.data;
          that.setData({
            orderDetail: orderDetail
          })
          wx.hideLoading();
        } else {
          wx.hideLoading();
          wx.showToast({
            title: msg,
            icon: 'none',
            duration: 2000,
            mask: true
          });
        }
      },
      fail: function () {
        wx.hideLoading();
        wx.showToast({
          title: "网络异常",
          icon: 'none',
          duration: 2000,
          mask: true
        });
      }
    })
  },

  /**
  * 立即发货
  */
  nowDeliver: function (e) {
    var that = this;
    var orderNo = e.currentTarget.dataset.orderno
    wx.showActionSheet({
      itemList: ['快递配送', '自己配送'],
      success: function (res) {
        var index = res.tapIndex;
        if (index == 0) {
          that.goWxml("../expressDelivery/expressDelivery?orderNo=" + orderNo + "");
        }
        if (index == 1) {
          that.goWxml("../ownDelivery/ownDelivery?orderNo=" + orderNo + "");
        }
      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })
  },

  /**
   * 立即发货
   */
  confimCollect: function (e) {
    var that = this;
    var orderNo = e.currentTarget.dataset.orderno;
    var userId = that.data.userId;

    wx.showLoading({
      title: '加载中',
      icon: 'loading',
      mask: true
    })
    wx.request({
      url: apiHost + 'hpp/order/confirmRecive',
      method: 'get',
      header: {
        'content-type': 'application/json'
      },
      data: {
        userId: userId,
        orderNo: orderNo
      },
      success: function (res) {
        console.log(res)
        var code = res.data.code;
        var msg = res.data.msg;
        if ("10000" == code) {
          that.goWxml("../leagueOrderList/leagueOrderList");    //跳转订单列表
        } else {
          wx.showToast({
            title: msg,
            icon: 'none',
            duration: 2000,
            mask: false
          })
        }
        wx.hideLoading();
      },
      fail: function () {
        wx.hideLoading();
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000,
          mask: false
        })
      }
    })
  },
  /**
   * 返回首页
   */
  goIndex:function(){
    var that = this;
    wx.showLoading({
      title: '跳转中',
      icon: 'loading',
      mask: true
    });

    wx.reLaunch({
      url: "../../index/index",
      success: function () {
        wx.hideLoading();   //隐藏加载loading
      },
    });
  },

  /**
  * 跳转 页面
  */
  goWxml: function (url) {
    var that = this;
    wx.showLoading({
      title: '跳转中',
      icon: 'loading',
      mask: true
    });

    wx.navigateTo({
      url: url,
      success: function () {
        wx.hideLoading();   //隐藏加载loading
      },
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  }
})